package com.wwinsoft.framework.dao.security;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.wwinsoft.framework.entity.security.Group;
import com.wwinsoft.framework.entity.security.Resource;
import com.wwinsoft.framework.entity.security.User;
import com.wwinsoft.modules.orm.hibernate.HibernateDao;

@Component
public class ResourceDao extends HibernateDao<Resource, Long> {

    public static final String QUERY_BY_RESOURCETYPE_WITH_AUTHORITY = "from Resource r left join fetch r.authorityList WHERE r.url is not null and r.resourceType='1' ORDER BY r.position ASC";

    /**
     * 查询URL类型的资源并预加载可访问该资源的授权信息.
     */
    @SuppressWarnings("unchecked")
    public List<Resource> getUrlResourceWithAuthorities() {
        Query query = createQuery(QUERY_BY_RESOURCETYPE_WITH_AUTHORITY);
        return distinct(query).list();
    }
	
}
